import Vue from 'vue'
import Vuex from 'vuex'
import * as actions from './action'
import * as getters from './getters'
import state from './state'
import mutations from './mutations'
import { recorder } from './plugins'
import createVuexAlong from 'vuex-along'

import { store as anovStore } from 'anov-core'
import defaultConfig from '@/assets/js/app/config'

//数据源默认使用用户配置
anovStore.dataSource.state.type = defaultConfig.dataSource.type
const projectId = require('../../package.json').projectId
const version = require('../../package.json').version
let urlStr=process.env.VUE_APP_DIRNAME&&process.env.VUE_APP_DIRNAME.replace(/\\/g, '/')
const anovDirname =
urlStr.substring(
  urlStr.lastIndexOf('/') + 1,
  urlStr.length
  )
// localStorage name
const lsn = `${anovDirname}_${projectId}_${version &&
  version.replace(/\./g, '-')}`
//每次通过mutation修改state的时候console.log
// import createLogger from 'vuex/dist/logger'
Vue.use(Vuex)
//如果是npm run dev的时候就是dev环境
//如果npm run build时候就是production环境
//检测在开发环境下修改state是不是通过mutation
const debug = process.env.NODE_ENV !== 'production'
export default new Vuex.Store({
  modules: {
    ...anovStore
  },
  actions,
  getters,
  state,
  mutations,
  strict: debug,
  plugins: [
    createVuexAlong({
      name: lsn,
      local: {
        list: [
          // AI
          'voiceFeedback',
          'voiceRecognize',
          'faceRecognize.isStart',
          'gestureRecognize',
          'lightSensor.isStart',
          // theme
          'theme',
          // sound
          'soundServer',
          // i18n
          'language.lang',
          // license
          'license',
          // animate
          'animate',
          // data source
          'dataSource',
          'loadTimes',
          !debug ? 'pageServer' : ''
        ],
        isFilter: false
      }
    }),
    recorder
  ]
})
